<?php include "Database_Open.php"; ?>
<?php

//get the q parameter from URL
$q=$_GET["q"];

$command = "select * from tProfile";
$result = $con->query($command);

if (strlen($q)>0)
{
    $hint="";
    while ($row = $result->fetch_array(MYSQLI_ASSOC))
    {
        if(stristr($row['sFirstName'].' '.$row['sLastName'], $q)){
            if ($hint=="")
            {
                $hint = "<div id=\"DDDD\" onclick=\"fillsearch('DDDDFFFF');\" onmouseover=\" highlight(this.id);\" onmouseout=\"unhighlight(this.id);\" class=\"searchcontent\">
                <div class=\"searchphoto\"><img src=\"IIII\" alt=\"image:NNNN\" ></div>
                <div id=\"DDDDFFFF\" class=\"searchname\">FFFF NNNN</div>
                </div>";
                
                $hint = str_replace("FFFF",$row['sFirstName'],$hint);
                $hint = str_replace("NNNN",$row['sLastName'],$hint);
                $hint = str_replace("IIII",$row['sPhoto'],$hint);
                $hint = str_replace("DDDD",$row['iProfile'],$hint);
            }
            else
            {
                $hint=$hint . "<br /><div id=\"DDDD\" onclick=\"fillsearch('DDDDFFFF');\" onmouseover=\" highlight(this.id);\" onmouseout=\"unhighlight(this.id);\" class=\"searchcontent\">
                <div class=\"searchphoto\"><img src=\"IIII\" alt=\"image:NNNN\" ></div>
                <div id=\"DDDDFFFF\" class=\"searchname\">FFFF NNNN</div>
                </div>";
                
                $hint = str_replace("FFFF",$row['sFirstName'],$hint);
                $hint = str_replace("NNNN",$row['sLastName'],$hint);
                $hint = str_replace("IIII",$row['sPhoto'],$hint);
                $hint = str_replace("DDDD",$row['iProfile'],$hint);
            }
        }
    }
}


// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
  {
  $response="no suggestion";
  }
else
  {
  $response=$hint;
  }

//output the response
echo $response;

?>
<?php include "Database_Close.php"; ?>